﻿<UserControl x:Class="MContracts.View.ContractorsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:converters="clr-namespace:MContracts.Classes.Converters"
             xmlns:Controls="clr-namespace:MContracts.Controls" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" DataContextChanged="UserControl_DataContextChanged">
    <Expander IsExpanded="{Binding IsMaximized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Background="{StaticResource Expander-Background-DocumentImage-Brush}">
        <Expander.Resources>
            <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueVisibility="Visible" FalseVisibility="Collapsed" />
            <converters:PersonConverter x:Key="ContractPersonConverter" />
            <converters:DateTimeToDateConverter x:Key="DateTimeToDateConverter" />
            <!--<converters:ContractdocConverter x:Key="ContractdocConverterExtractName" />-->
            <converters:ValidToColorConverter x:Key="DocValidToColorConverter"  ValidBrush="Green" NotValidBrush="Red" DefaultBrush="{x:Null}"/>
            <converters:ValidToColorConverter x:Key="DocActiveToColorConverter"  ValidBrush="Green" NotValidBrush="Black" DefaultBrush="OrangeRed"/>
            <converters:BoolToDoubleConverter x:Key="BoolToOpacityConverter" TrueValue="1" FalseValue="0.5" DefaultValue="1"/>
            <converters:BooleanToStringConverter x:Key="BooleanToActiveStringConverter" TrueMessage="Действующий"  FalseMessage="Завершён" DefaultMessage="Не задано"/>
            <DataTemplate x:Key="ContractorPersonItemTemplate">
                <!--<Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="2"  >-->
                <StackPanel>
                    <WrapPanel>
                        <Image Width="25" Height="25" Source="/MContracts;component/Resources/Boss.png" ToolTip="Право подписи от первого лица" Opacity="{Binding Path=Contractheadauthority, Converter={StaticResource BoolToOpacityConverter}}"></Image>
                        <Image Margin="5,0,0,0" Width="25" Height="25" Source="/MContracts;component/Resources/ico-terms.png" ToolTip="Право подписи актов" Opacity="{Binding Path=Actsignauthority, Converter={StaticResource BoolToOpacityConverter}}"></Image>
                        <Label Margin="5,0,0,0"  FontWeight="Bold" Content="{Binding}" Foreground="{Binding Valid, Converter={StaticResource DocValidToColorConverter}}"></Label>

                        <!--<CheckBox Margin="5,0,0,0" IsEnabled="False" Content="Право подписи от первого лица" IsChecked="{Binding Path=Contractheadauthority}"></CheckBox>
                    <CheckBox Margin="5,0,0,0" IsEnabled="False" Content="Право подписи актов" IsChecked="{Binding Path=Actsignauthority}"></CheckBox>-->

                    </WrapPanel>
                </StackPanel>
                <!--</Border>-->
            </DataTemplate>

            <DataTemplate x:Key="EnterpriseAuthorityItemTemplate">
                <!--<Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="2">-->
                <StackPanel>
                    <WrapPanel>
                        <Label VerticalAlignment="Center" FontWeight="Bold" FontSize="14" Content="{Binding Num}" Foreground="{Binding Valid, Converter={StaticResource DocValidToColorConverter}}"></Label>
                        <Label VerticalAlignment="Center" Margin="5,0,0,0"  Content="{Binding Employee}"></Label>
                        <Label VerticalAlignment="Center" Margin="5,0,0,0"  Content="{Binding Authority}"></Label>
                    </WrapPanel>
                    <WrapPanel Margin="10,0,0,0">
                        <Label Margin="0,0,0,0"  Content="Действует с"></Label>
                        <Label Margin="2,0,0,0" Content="{Binding StringFormat=\{0:d\}, Path=Validfrom}"></Label>
                        <Label Content="по"></Label>
                        <Label Margin="2,0,0,0"  Content="{Binding StringFormat=\{0:d\}, Path=Validto}"></Label>
                    </WrapPanel>
                </StackPanel>
                <!--</Border>-->
            </DataTemplate>
        </Expander.Resources>

        <Expander.Header>
            <WrapPanel>
                <Image Source="/MContracts;component/Images/text_editor.png" Width="30"></Image>
                <Label Content="{Binding Caption}"></Label>
            </WrapPanel>
        </Expander.Header>

        <Expander.Content>
            <Border BorderThickness="4" CornerRadius="4" Padding="2" Background="{StaticResource ResourceKey=Expander-Background-Brush}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="45"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="*"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ComboBox ToolTip="Фильтр типов контрагентов" HorizontalAlignment="Stretch" Grid.ColumnSpan="3" VerticalAlignment="Center" ItemsSource="{Binding Contractortypes}" SelectedItem="{Binding SelectedContractortype}"></ComboBox>
                    <TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" d:LayoutOverrides="Height" ><Run Language="ru-ru" Text="Контрагенты договора"/></TextBlock>
                    <TextBlock Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" Width="83.26"><Run Language="ru-ru" Text="Контрагенты"/></TextBlock>
                    <ListBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding Contractors}" SelectedItem="{Binding SelectedContractor}" MaxHeight="350"></ListBox>
                    <ListBox Grid.Row="2" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding ContractContractors}" SelectedItem="{Binding SelectedContractContractor}" MaxHeight="350"></ListBox>
                    <Controls:CommandsControl x:Name="commandsControl" Orientation="Vertical"  Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"></Controls:CommandsControl>
                  
                    <ComboBox ToolTip="Персона контрагента" Margin="0,5,0,5" Grid.Row="3" Grid.ColumnSpan="3" ItemsSource="{Binding Path=Persons, Mode=OneWay}" 
					SelectedItem="{Binding Path=ContractObject.Person}"
					ItemTemplate="{StaticResource ResourceKey=ContractorPersonItemTemplate}" />
             
                    <ComboBox ToolTip="Основание для промгаза" Margin="0,5,0,5" Grid.Row="4" Grid.ColumnSpan="3" ItemsSource="{Binding Enterpriseauthorities}" 
					SelectedItem="{Binding ContractObject.Enterpriseauthority}" 
					ItemTemplate="{StaticResource ResourceKey=EnterpriseAuthorityItemTemplate}" x:Name="EnterpriseauthorityComboBox" />
             
                </Grid>
            </Border>

        </Expander.Content>



    </Expander>
</UserControl>
